Stikman fails.py
Stikman fails.py
—
Python Source,
6 KB (6269 bytes)
Dateiinhalt
from visual import *
scene.tittel="Just Baum"
scene.autoscale=False
scene.userzoom= False
scene.userspin= False
scene.center=(0,20,0)
tex1 = materials.texture(data=materials.loadTGA("Nadel"),mapping = "rectangular")
tex2 = materials.texture(data=materials.loadTGA("Gras"),mapping = "sign")
scene.forward=(0.0,-0.5,-1.0)
scene.stereo = "redcyan"
#Klassen
class man(frame):
def __init__ (self,pos=(0,0,0)):
frame.__init__(self)
self.koerper=cone (frame=self,pos=(0,0,0),radius=3,length=15,color=color.blue,axis=(0,1,0))
self.kopf=sphere(frame=self,pos=(0,12,0),radius=3)
self.muni=0
self.anzeige=label(frame=self ,pos=(0,15,0),text="Pfeile" + str (self.muni))
#self.front=arrow(frame=self,pos=(0,8,0),axis=(10,0,0),shaftwidth=10)
self.pos=pos
def bewegen (self,schritt):
self.pos +=schritt
for obj in Kliste:
if obj.kollision (self.pos.x,self.pos.z):
self.pos -=schritt
for obj in Eliste:
if obj.kollision (self.pos.x,self.pos.z,self.pos.y):
obj.pos.y=-20
self.muni+=1
self.anzeige.text="Pfeile" + str (self.muni)
class Baum (frame):
def __init__(self,pos=(0,0,0)):
frame.__init__(self)
self.stamm=cylinder(frame=self,pos=(0,0,0),radius=2,axis=(0,5,0),length=10,material=materials.wood)
self.krone=cone (frame=self,pos=(0,8,0),axis=(0,5,0),radius=6,length=20,material=tex1)
self.pos=pos
def kollision (self,x,z):
if x < self.pos.x +4 and x > self.pos.x -4 and z < self.pos.z +4 and z > self.pos.z -4:
print("!!!!!!")
return True
else:
return False
class Haus (frame):
def __init__(self,pos=(0,0,0)):
frame.__init__(self)
self.mauern=box (frame=self,pos=(0,0,0),length=60,height=40,width=30,color=color.white)
self.dach=pyramid (frame=self,pos=(0,20,0),size=(15,65,35),axis=(0,5,0),color=color.red)
self.pos=pos
def kollision (self,x,z):
if x < self.pos.x +30 and x > self.pos.x -30 and z < self.pos.z +15 and z > self.pos.z -15:
print("!!!!!!")
return True
else:
return False
class Zaun (frame):
def __init__(self,pos=(0,0,0)):
frame.__init__(self)
self.latte1=arrow(frame=self,pos=(-5,0,0),axis=(0,5,0),length=15,color=(0,0,0))
self.latte1=arrow(frame=self,pos=(0,0,0),axis=(0,5,0),length=15,color=(0,0,0))
self.latte1=arrow(frame=self,pos=(5,0,0),axis=(0,5,0),length=15,color=(0,0,0))
self.latte1=arrow(frame=self,pos=(-10,0,0),axis=(0,5,0),length=15,color=(0,0,0))
self.latte1=arrow(frame=self,pos=(10,0,0),axis=(0,5,0),length=15,color=(0,0,0))
self.balken=box(frame=self,pos=(0,6,0),length=20,height=2,width=1,color=(0,0,0))
self.pos=pos
def kollision (self,x,z):
if x < self.pos.x +10 and x > self.pos.x -10 and z < self.pos.z +2 and z > self.pos.z -2:
print("!!!!!!")
return True
else:
return False
class PfeilD (frame):
def __init__(self,pos=(0,0,0)):
frame.__init__(self)
self.balken=box(frame=self,pos=(5,6,0),length=10,height=2,width=1,material=materials.wood)
self.spitze=pyramid (frame=self,pos=(10,6,0),size=(6,3,3),material=materials.rough)
self.federn=pyramid (frame=self,pos=(0,6,0),size=(6,3,3),color=color.red)
self.pos=pos
def kollision (self,x,z,y):
if x < self.pos.x +10 and x > self.pos.x -10 and z < self.pos.z +10 and z > self.pos.z -10 and y < self.pos.y +10 and y > self.pos.y -10:
print("!!!!!!")
return True
else:
return False
#V
V = []
for i in range(0,60):
if random.randint(0,50) < 25:
V.append(random.randint(-225,-25))
else:
V.append(random.randint(25,225))
#konstruktor
Man1 = man (pos=(0,0,0))
Man2 = man (pos=(10,0,0))
Boden= box (pos=(0,0,0),length=1,height=500,width=500,material=tex2)
Boden.rotate(angle=pi/2, axis=(0,0,1))
Baum1=Baum (pos=(V[0],0,V[1]))
Baum2=Baum (pos=(V[2],0,V[3]))
Baum3=Baum (pos=(V[4],0,V[5]))
Baum4=Baum (pos=(V[6],0,V[7]))
Baum5=Baum (pos=(V[8],0,V[9]))
Baum6=Baum (pos=(V[10],0,V[11]))
Baum7=Baum (pos=(V[48],0,V[49]))
Baum8=Baum (pos=(V[50],0,V[51]))
Baum9=Baum (pos=(V[52],0,V[53]))
Baum10=Baum (pos=(V[54],0,V[55]))
Baum11=Baum (pos=(V[56],0,V[57]))
Baum12=Baum (pos=(V[58],0,V[59]))
Haus1=Haus (pos=(V[12],0,V[13]))
Haus2=Haus (pos=(V[14],0,V[15]))
Haus3=Haus (pos=(V[16],0,V[17]))
Haus4=Haus (pos=(V[18],0,V[19]))
Haus5=Haus (pos=(V[20],0,V[21]))
Haus6=Haus (pos=(V[22],0,V[23]))
Zaun1=Zaun (pos=(V[24],0,V[25]))
Zaun2=Zaun (pos=(V[26],0,V[27]))
Zaun3=Zaun (pos=(V[28],0,V[29]))
Zaun4=Zaun (pos=(V[30],0,V[31]))
Zaun5=Zaun (pos=(V[32],0,V[33]))
Zaun6=Zaun (pos=(V[34],0,V[35]))
PfeilD1=PfeilD (pos=(V[36],0,V[37]))
PfeilD2=PfeilD (pos=(V[38],0,V[39]))
PfeilD3=PfeilD (pos=(V[40],0,V[41]))
PfeilD4=PfeilD (pos=(V[42],0,V[43]))
PfeilD5=PfeilD (pos=(V[44],0,V[45]))
PfeilD6=PfeilD (pos=(V[46],0,V[47]))
Kliste = [Baum1,Baum2,Baum3,Baum4,Baum5,Baum6,Baum7,Baum8,Baum9,Baum10,Baum11,Baum12,Haus1,Haus2,Haus3,Haus4,Haus5,Haus6,Zaun1,Zaun2,Zaun3,Zaun4,Zaun5,Zaun6]
Eliste = [PfeilD1,PfeilD2,PfeilD3,PfeilD4,PfeilD5,PfeilD6]
#Bewegung spieler
def richtung(x):
return {
0: (0.0,-0.5,-1.0),
1: (1.0,-0.5,0.0),
2: (0.0,-0.5,1.0),
3: (-1.0,-0.5,0.0),
}[x]
def brichtung(x):
return {
0: (0,0,-1),
1: (1,0,0),
2: (0,0,1),
3: (-1,0,0),
}[x]
Richtung=0
while True:
rate(30)
if scene.kb.keys:
zeichen = scene.kb.getkey()
if zeichen == "up":
Man1.bewegen(brichtung(x=Richtung))
#richtung
if zeichen == "right":
Richtung += 1
if Richtung > 3:
Richtung=0
scene.forward=(richtung(x=Richtung))
if zeichen == "left":
Richtung += -1
if Richtung < 0:
Richtung=3
scene.forward=(richtung(x=Richtung))
scene.center=Man1.kopf.pos+Man1.pos+(0,8,0)
#scene.forward=(0,1,0)
print scene.center